package tk.xboot.boot.controller;

import org.springframework.http.client.OkHttp3ClientHttpRequestFactory;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;
import tk.xboot.boot.web.WebResult;

import java.util.Map;

@RestController
@RequestMapping("h2")
public class H2Controller {
    @GetMapping
    public String hello() {
        RestTemplate http2Template = new RestTemplate(new OkHttp3ClientHttpRequestFactory());
        RestTemplate http11Template = new RestTemplate();

        String http11Response = http11Template.getForObject("https://http2.akamai.com/", String.class);
        String http2Response = http2Template.getForObject("https://http2.akamai.com/", String.class);

        return "HTTP/1.1 : " + http11Response.contains("You are using HTTP/2 right now!") + "<br/>" +
                "HTTP/2 : " + http2Response.contains("You are using HTTP/2 right now!");
    }

    @GetMapping("hi")
    public String hi() {
        return "Hi guys.";
    }

    @GetMapping("p")
    public String hip() {
        return "p.";
    }



    @PostMapping(value = "echo")
    @ResponseBody
    public WebResult<Map<String,Object>> echo(@RequestBody Map<String,Object> map){
        System.out.println(map.get("uid"));
        if (map.get("uid").equals(1)) {
            return WebResult.ok(map);
        }
        return WebResult.err(33);
    }


}
